package cn.xxm.activiti7_workflow;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;

/**
 * @program: activiti7_workflow
 * @link: 55864455@qq.com
 * @author: Mr.Xxm
 * @create: 2020-09-29 12:13
 **/
@SpringBootTest
public class Part1_Deployment {

    @Autowired
    private RepositoryService repositoryService;

    /**
     * 功能描述:部署流程
     * @param: 插入 act_re_deployment , act_ge_bytearray ,act_re_procdef
     * @return:
     * @author: 
     * @date: 2020/9/29 16:16
     */
    @Test
    public void initDeploymentBPMN(){

        String filename = "BPMN/Part8_ProcessRuntime.bpmn";
        //String pngname = "BPMN/Part1_Deployment.png";

        Deployment deployment = repositoryService.createDeployment()
                                .addClasspathResource(filename)
                                //.addClasspathResource(pngname)
                                .disableSchemaValidation() //禁用架构验证
                                .name("流程部署测试Runtime")
                                .deploy();

        System.out.println("deployment.getName() = " + deployment.getName());
    }

    //通过ZIP部署流程
    @Test
    public void initDeploymentZIP() {
        InputStream fileInputStream = this.getClass()
                .getClassLoader()
                .getResourceAsStream("BPMN/Part1_DeploymentV2.zip");
        ZipInputStream zip=new ZipInputStream(fileInputStream);
        Deployment deployment=repositoryService.createDeployment()
                .addZipInputStream(zip)
                .name("流程部署测试zip")
                .deploy();
        System.out.println(deployment.getName());
    }

    //查询流程部署
    @Test
    public void getDeployments() {
        List<Deployment> list = repositoryService.createDeploymentQuery().list();
        for(Deployment dep : list){
            System.out.println("Id："+dep.getId());
            System.out.println("Name："+dep.getName());
            System.out.println("DeploymentTime："+dep.getDeploymentTime());
            System.out.println("Key："+dep.getKey());
        }

    }
}
